
export default {
  data() {
    return {
      lineOptions: {
        legend: {
          data: ["任务延迟数", "任务计划总耗时", "任务实际总耗时", "任务完成率", "任务延迟率"],
          top: "2%",
          right: "5%"
        },

        grid: {
          top: "10%",
          left: "20%",
          right: "5%",
          bottom: "2%",
          containLabel: true
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: []
        },
        yAxis: {
          type: "value"
        },
        series: [
          {
            name: "任务延迟数",
            type: "line",
            stack: "Total",
            data: []
          },
          {
            name: "任务计划总耗时",
            type: "line",
            stack: "Total",
            data: []
          },
          {
            name: "任务实际总耗时",
            type: "line",
            stack: "Total",
            data: []
          },
          {
            name: "任务完成率",
            type: "line",
            stack: "Total",
            data: []
          },
          {
            name: "任务延迟率",
            type: "line",
            stack: "Total",
            data: []
          },
        ]
      }
    }
  },
  methods: {
    initLineChart(data) {
      if (this.myChart) {
        this.myChart.dispose();
        this.myChart = null;
      }
      const xAxisData = []
      for (const s of this.lineOptions.series) {
        s.data = []
      }
      for (const item of data) {
        const { delayCount, sumPlanAlongByFinish, sumAlongByFinish, finishRate, delayRate, taskDate } = item || {}
        xAxisData.push(taskDate)
        this.lineOptions.series[0].data.push(delayCount)
        this.lineOptions.series[1].data.push(sumPlanAlongByFinish)
        this.lineOptions.series[2].data.push(sumAlongByFinish)
        this.lineOptions.series[3].data.push(finishRate)
        this.lineOptions.series[4].data.push(delayRate)
      }
      this.lineOptions.xAxis.data = xAxisData
    }
  }
}
